package com.ccc.boot.pojo;

import com.ccc.boot.exception.BusinessException;
import com.ccc.boot.response.ResponseCode;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 查询请求参数对象
 *
 * @author superC
 * @version 0.1.0
 * @date 2022/4/6
 */

public class Query extends LinkedHashMap<String, Object> {

    private static final long serialVersionUID = 2425759536834701489L;

    private static final String PARAM_PAGE = "page";

    private static final String PARAM_PAGE_SIZE = "pageSize";

    /**
     * 当前页
     */
    private int current = 1;

    /**
     * 每页显示条数
     */
    private int size = 10;

    public Query(Map<String, Object> params) {
        this.putAll(params);
        //分页参数
        if (params.get(PARAM_PAGE) == null) {
            throw new BusinessException(ResponseCode.PARAM_NOT_COMPLETE);
        }
        if (params.get(PARAM_PAGE_SIZE) == null) {
            throw new BusinessException(ResponseCode.PARAM_NOT_COMPLETE);
        }
        this.current = Integer.parseInt(params.get(PARAM_PAGE).toString());
        this.size = Integer.parseInt(params.get(PARAM_PAGE_SIZE).toString());
        this.remove(PARAM_PAGE);
        this.remove(PARAM_PAGE_SIZE);
    }

    public int getCurrent() {
        return current;
    }

    public void setCurrent(int current) {
        this.current = current;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }
}